# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/5/4 17:40
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/h5_server.git
# @File    : __init__.py.py
# @Software: PyCharm
# @Version: 3.5.4
import logging.handlers
import os
try:
	from configs import current_config
except Exception as e:
	print(e)
	# raise FileExistsError


app_path = current_config.DEPLOY_PATH
app_id = current_config.APPLICATION_ID


# logging初始化工作
logging.basicConfig()

# nor的初始化工作
file_log = logging.getLogger("my_log")
file_log.setLevel(logging.INFO)


# 添加TimedRotatingFileHandler到nor
# 定义一个1分钟换一次log文件的handler
dir_path = os.path.join(app_path, 'logs/')
if not os.path.exists(dir_path):
	os.makedirs(dir_path)

file_path = os.path.join(app_path, 'logs/' + app_id + '_log')
if not os.path.exists(file_path):
	file = open(file_path, 'w')
	file.close()


filehandler = logging.handlers.TimedRotatingFileHandler(file_path, 'D', 1, 0)
# 设置后缀名称，跟strftime的格式一样
filehandler.suffix = "%Y%m%d-%H%M.log"
log_fmt = '%(asctime)s\t%(levelname)s: %(message)s'
formatter = logging.Formatter(log_fmt)
filehandler.setFormatter(formatter)
file_log.addHandler(filehandler)
file_log.info('log file in ' + file_path)

